//Sunday, November 15 2009
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class Undo
{
public:
	string getText(vector <string> commands, vector <int> time)
	{
		string ret = "";
		vector<string> A;
		for(int i=0; i<commands.size(); i++)
		{
			if(commands[i][0] == 't')
			{
				A.push_back(ret);
				ret += commands[i][5];
			}
			else
			{
				A.push_back(ret);
				stringstream s(commands[i]);
				string temp;
				int sec;
				s >> temp >> sec;
				for(int j=i-1; j>=0; j--)
					if(time[i] - time[j] <= sec)
						ret = A[j];
			}
		}
		return ret;
	}
};